package com.ruoyi.wechat.api;

import com.ruoyi.wechat.domain.CCampsite;
import com.ruoyi.wechat.service.ICCampsiteService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.service.ICCampsiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wechat/campsite")
public class WxCampsiteController extends BaseController
{
    @Autowired
    private ICCampsiteService campsiteService;

    /**
     * 查询营位列表
     */
    @GetMapping("/list")
    public AjaxResult list(CCampsite campsite)
    {
//        startPage();
        List<CCampsite> list = campsiteService.selectCCampsiteList(campsite);
//
        return success(list);
    }
    /**
     * 获取营位详细信息
     */
    @GetMapping(value = "/{campsiteId}")
    public AjaxResult getInfo(@PathVariable("campsiteId") String campsiteId)
    {
        return success(campsiteService.selectCCampsiteByCampsiteId(campsiteId));
    }

    /**
     * 新增营位
     */
    @PreAuthorize("@ss.hasPermi('camp:campsite:add')")
    @Log(title = "营位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CCampsite[] campsites)
    {
        return toAjax(campsiteService.insertCCampsites(campsites));
    }

//    @PostMapping
//    public AjaxResult add(@RequestBody CCampsite campsite)
//    {
//        return toAjax(campsiteService.insertCCampsite(campsite));
//    }

    /**
     * 修改营位
     */
    @Log(title = "营位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CCampsite campsite)
    {
        return toAjax(campsiteService.updateCCampsite(campsite));
    }

    /**
     * 删除营位
     */
    @DeleteMapping("/{campsiteId}")
    public AjaxResult remove(@PathVariable String[] campsiteId)
    {
        return toAjax(campsiteService.deleteCCampsiteByCampsiteIds(campsiteId));
    }
}
